package com.lzx.lizhenxing.user.comtroller;

import com.lzx.lizhenxing.common.vo.CommonResult;
import com.lzx.lizhenxing.common.vo.PageVo;
import com.lzx.lizhenxing.user.model.UserOrderModel;
import com.lzx.lizhenxing.user.param.CreateOrderParam;
import com.lzx.lizhenxing.user.param.OrderQueryParam;
import com.lzx.lizhenxing.user.param.QueryOrderParam;
import com.lzx.lizhenxing.user.param.UpdateTimeParam;
import com.lzx.lizhenxing.user.service.UserOrderService;
import com.lzx.lizhenxing.user.vo.OrderPageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user/order")
public class UserOrderController {

    @Resource
    private UserOrderService userOrderService;

    @PostMapping("/createOrder")
    public CommonResult createOrder(@RequestBody CreateOrderParam Param){
        Long orderId = userOrderService.createOrder(Param);
        return CommonResult.success(orderId);
    }

    @PostMapping("/getPageOrder")
    public CommonResult getPageOrder(@RequestBody OrderQueryParam Param){
        PageVo<OrderPageVo> pageList = userOrderService.getPageOrder(Param);
        return CommonResult.success(pageList);
    }

    @GetMapping("/cancelOrder")
    public CommonResult cancelOrder(@RequestParam Long id){
        userOrderService.cancelOrder(id);
        return CommonResult.success();
    }

    @PostMapping("/updateDeliveryTime")
    public CommonResult updateDeliveryTime(@RequestBody UpdateTimeParam Param){
        userOrderService.updateDeliveryTime(Param);
        return CommonResult.success();
    }

    @GetMapping("/deleteOrderInfo")
    public CommonResult deleteOrderInfo(@RequestParam Long id){
        userOrderService.deleteOrderInfo(id);
        return CommonResult.success();
    }

    @PostMapping("/getOneOrder")
    public CommonResult getOneOrder(@RequestBody QueryOrderParam Param){
        UserOrderModel order = userOrderService.getOneOrder(Param);
        return CommonResult.success(order);
    }

    @GetMapping("/payByPoint")
    public CommonResult payByPoint(@RequestParam Long orderId){
        userOrderService.payByPoint(orderId);
        return CommonResult.success();
    }
}
